var Script = function () {

    $.validator.setDefaults({
        submitHandler: function () {
          alert("提交");
        }
    });

    $().ready(function () {
        // validate the comment form when it is submitted
        $("#commentForm").validate();

        // validate signup form on keyup and submit
        $("#signupForm").validate({
            rules: {
                //人员验证
                Employeename: "required",
                logonname: "required",
                Employeepassword: {
                    required: true,
                    minlength: 5
                },
                Employeephone: {
                    required: true,
                    minlength: 10
                },



                //园区验证
                Parknumber: "required",
                Parkname: "required",
                ParkAddress: "required",
                Parkcontact: "required",
                Parkphone: {
                    required: true,
                    minlength: 10
                },

                //巡查验证
                BranchOffice: "required",
                Tasknumber: "required",
                Taskname: "required",
                Taskdescription: "required",
                // 产品验证
                Expertname: "required",
                Expertnumber: "required",
                //公告验证
                Lowername: "required",



                firstname: "required",
                lastname: "required",
                username: {
                    required: true,
                    minlength: 2
                },
                password: {
                    required: true,
                    minlength: 5
                },
                confirm_password: {
                    required: true,
                    minlength: 5,
                    equalTo: "#password"
                },
                email: {
                    required: true,
                    email: true
                },
                topic: {
                    required: "#newsletter:checked",
                    minlength: 2
                },
                agree: "required"
            },
            messages: {
                //通知公告
                code:{
                    required:"请输入编号",
                    minlength:"编号不能小于5位数"
                },
                title:{
                    required:"请输入标题",
                    rangelength:"标题不能小于5或大于30位数"
                },
                content:{
                    required:"请输入内容"
                },

                // 员工验证提示
                Employeename: "请输入名称",
                logonname: "请输入登录名称",
                Employeepassword: {
                    required: "请输入登录密码",
                    minlength: "登录密码不能小于6位数"
                },
                Employeephone: {
                    required: "请输入手机号码",
                    minlength: "请输入正确的手机号码"
                },
                // 员工验证提示结束
                // 园区验证提示结束
                Parknumber: "请输入园区编号",
                Parkname: "请输入园区名称",
                ParkAddress: "请输入园区地址",
                Parkcontact: "请输入园区联系人",
                Parkphone: {
                    required: "请输入手机号码",
                    minlength: "请输入正确的手机号码"
                },
                // 园区验证提示结束
                // 巡查验证提示
                BranchOffice: "请输入巡查任务",
                Tasknumber: "请输入任务编号",
                Taskname: "请输入任务名称",
                Taskdescription: "任务描述",
                //巡查验证提示结束
                // 产品验证提示
                Expertnumber: "请输入产品编号",
                Expertname: "请输入产品名称",
                //产品验证提示结束
                // 产品验证提示
                Lowername: "请输入下发人",
                content: "请输入内容",
                //产品验证提示结束
                title: "请输入标题",

                firstname: "Please enter your firstname",
                lastname: "Please enter your lastname",
                username: {
                    required: "Please enter a username",
                    minlength: "Your username must consist of at least 2 characters"
                },
                password: {
                    required: "Please provide a password",
                    minlength: "Your password must be at least 5 characters long"
                },
                confirm_password: {
                    required: "Please provide a password",
                    minlength: "Your password must be at least 5 characters long",
                    equalTo: "Please enter the same password as above"
                },
                email: "Please enter a valid email address",
                agree: "Please accept our policy"
            }
        });

        // propose username by combining first- and lastname
        $("#username").focus(function () {
            var firstname = $("#firstname").val();
            var lastname = $("#lastname").val();
            if (firstname && lastname && !this.value) {
                this.value = firstname + "." + lastname;
            }
        });

        //code to hide topic selection, disable for demo
        var newsletter = $("#newsletter");
        // newsletter topics are optional, hide at first
        var inital = newsletter.is(":checked");
        var topics = $("#newsletter_topics")[inital ? "removeClass" : "addClass"]("gray");
        var topicInputs = topics.find("input").attr("disabled", !inital);
        // show when newsletter is checked
        newsletter.click(function () {
            topics[this.checked ? "removeClass" : "addClass"]("gray");
            topicInputs.attr("disabled", !this.checked);
        });
    });


}();